/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TextInputDlg.java
 *
 * Created on Aug 4, 2010, 10:11:48 AM
 */

package gralej.gui;

import javax.swing.JTextPane;

/**
 *
 * @author Martin
 */
public class TextInputDlg extends javax.swing.JDialog {

    public static interface Handler {
        void processText(String text);
    }

    private Handler _handler;

    public TextInputDlg(java.awt.Frame parent, Handler handler,
            String title, String okButtonText, String text) {
        this(parent, false, handler, title, okButtonText, "Close", text);
    }

    /** Creates new form TextInputDlg */
    public TextInputDlg(java.awt.Frame parent, boolean modal, Handler handler,
            String title, String okButtonText, String closeButtonText, String text) {
        super(parent, modal);
        _handler = handler;
        initComponents();
        setTitle(title);
        _ok.setText(okButtonText);
        if (okButtonText.length() > 0)
            _ok.setMnemonic(okButtonText.charAt(0));
        _close.setText(closeButtonText);
        _textPane.setText(text);
        _textPane.setCaretPosition(0);
    }

    public JTextPane getTextPane() {
        return _textPane;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        _close = new javax.swing.JButton();
        _ok = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        _textPane = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setLocationByPlatform(true);

        _close.setText("Close");
        _close.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _closeActionPerformed(evt);
            }
        });

        _ok.setText("OK");
        _ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _okActionPerformed(evt);
            }
        });

        _textPane.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
        jScrollPane1.setViewportView(_textPane);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 645, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(_ok)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(_close)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {_close, _ok});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_close)
                    .addComponent(_ok))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void _okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__okActionPerformed
        _handler.processText(_textPane.getText());
    }//GEN-LAST:event__okActionPerformed

    private void _closeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__closeActionPerformed
        dispose();
    }//GEN-LAST:event__closeActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _close;
    private javax.swing.JButton _ok;
    private javax.swing.JTextPane _textPane;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
